package com.venutech.gongan.entity;

import javax.xml.bind.annotation.adapters.XmlAdapter;

public class CDataAdapter extends XmlAdapter<String, String> {
    //从javabean到xml的适配方法
    @Override
    public String marshal(String str) throws Exception {
        return "<![CDATA[and xm='" + str+ "']]>";
    }

    //从xml到javabean的适配方法
    @Override
    public String unmarshal(String str) throws Exception {
        if("<![CDATA[]]>".equals(str)){
            return "";
        }
        String v1=null;
        String v2=null;
        String subStart="<![CDATA[";
        int a=str.indexOf(subStart);
        if(a>0){
            v1=str.substring(subStart.length(),str.length());
        }else {
            return str;
        }
        String subEnd="]]>";
        int b=v1.indexOf(subEnd);
        if(b>=0){
            v2=v1.substring(0,b);
        }
        return v2;
    }
}
